﻿namespace Guia.Elements
{
    using System.Windows.Automation;
    using Guia.Elements.PatternServants;
    using Guia.Locator;

    /// <summary>
    /// This class represents a particular cell within a DataGrid of the ListView.
    /// Attention: cells cant be looked up. They can only be accessed by the DataGrid directly. 
    /// </summary>
    public class DataGridCell_ListView : AbstractDataGridCell, IGridItem
    {
        /// <summary>
        /// Represents a helper-servant for the GridItem-pattern.
        /// </summary>
        private readonly IGridItem gridItemServant;

        /// <summary>
        /// Initializes a new instance of the DataGridCell_ListView class for the WPF Toolkit. 
        /// </summary>
        /// <param name="automationElement">The AutomationElement representating the DataGridCell.</param>
        public DataGridCell_ListView(AutomationElement automationElement)
            : base(automationElement)
        {
            this.gridItemServant = new GridItemImpl(this);
        }

        /// <summary>
        /// Gets the default-condition to find a control by its type.
        /// </summary>
        public static SearchCondition ControlTypeCondition
        {
            get { return SearchCondition.ByControlType(ControlType.Text); }
        }

        /// <summary>
        /// Gets the number of the cell's column.
        /// </summary>
        public int Column
        {
            get
            {
                return this.gridItemServant.Column;
            }
        }

        /// <summary>
        /// Gets the number of the cell's row.
        /// </summary>
        public int Row
        {
            get
            {
                return this.gridItemServant.Row;
            }
        }

        /// <summary>
        /// Gets the cell's column-span.
        /// </summary>
        public int ColumnSpan
        {
            get
            {
                return this.gridItemServant.ColumnSpan;
            }
        }

        /// <summary>
        /// Gets the cell's row-span.
        /// </summary>
        public int RowSpan
        {
            get
            {
                return this.gridItemServant.RowSpan;
            }
        }

        /// <summary>
        /// Gets a textual value of this cell.
        /// </summary>
        /// <returns>String representation of this cell</returns>
        protected override string GetTextValue()
        {
            return this.Name;
        }
    }
}
